//
//  HNSH_GroupChatInfoViewController.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/2/17.
//

//刷新群聊信息页面
#define kRefreshGroupInfo @"kRefreshGroupInfo"

#import "HNSH_GroupChatInfoViewController.h"

//view
#import "HNSH_GroupMembersChangeCell.h"
#import "HNSH_GroupMembersCommonCell.h"
#import "HNSH_GroupChatInfoSwitchCell.h"
#import "HNSH_GroupChatInfoCommonCell.h"
#import "HNSH_GroupChatInfoMoreFooterView.h"
#import "HNSH_GroupChatInfoChatFooterView.h"

//model
#import "HNSH_GroupInfoModel.h"
#import "HNSH_ChatFriendModel.h"

//vc
#import "HNSH_GroupMembersViewController.h"
#import "HNSH_ChatFriendDetailViewController.h"     //好友信息
#import "HNSH_AddMembersViewController.h"           //添加群成员
#import "HNSH_DeleteMembersViewController.h"        //删除群成员
#import "HNSH_GroupNameViewController.h"            //群聊名称
#import "HNSH_GroupQRCodeViewController.h"          //群二维码
#import "HNSH_GroupNoticeViewController.h"          //群公告
#import "HNSH_GroupManageViewController.h"          //群管理
#import "HNSH_GroupRemarkViewController.h"          //群备注

static CGFloat showMoreFooterCount = 18;

@interface HNSH_GroupChatInfoViewController ()<UINavigationControllerDelegate,UIImagePickerControllerDelegate>
/** */
@property (nonatomic, copy)NSArray * membersArray;
/** */
@property (nonatomic, copy)NSArray * showMembersArray;
/** */
@property (nonatomic, copy)NSArray <NSArray *> * titlesArray;
/** */
@property (nonatomic, assign)NSInteger role;
/** */
@property (nonatomic, assign)NSInteger totalCount;
/** */
@property (nonatomic, strong)HNSH_GroupInfoUserModel * groupModel;

@end

static NSString *HNSH_GroupMembersChangeCellID = @"HNSH_GroupMembersChangeCellID";
static NSString *HNSH_GroupMembersCommonCellID = @"HNSH_GroupMembersCommonCellID";
static NSString *HNSH_GroupChatInfoSwitchCellID = @"HNSH_GroupChatInfoSwitchCellID";
static NSString *HNSH_GroupChatInfoCommonCellID = @"HNSH_GroupChatInfoCommonCellID";

static NSString *HNSH_GroupChatInfoMoreFooterViewID = @"HNSH_GroupChatInfoMoreFooterViewID";
static NSString *HNSH_GroupChatInfoChatFooterViewID = @"HNSH_GroupChatInfoChatFooterViewID";

@implementation HNSH_GroupChatInfoViewController

//MARK: Cycle Methods
- (void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)viewDidLoad{
    [super viewDidLoad];
        
    [self showNavTitle:[NSString stringWithFormat:@"%@", @"聊天信息"] showLeftItem:YES];
    
    [self addObs];
    
    [self addAllViews];
    
    [self configCollection];
}

- (void)configCollection {
    self.collectionView.backgroundColor = [UIColor appWhiteLabelColor];
    
    [self.collectionView registerClass:[HNSH_GroupMembersChangeCell class] forCellWithReuseIdentifier:HNSH_GroupMembersChangeCellID];
    [self.collectionView registerClass:[HNSH_GroupMembersCommonCell class] forCellWithReuseIdentifier:HNSH_GroupMembersCommonCellID];
    [self.collectionView registerClass:[HNSH_GroupChatInfoSwitchCell class] forCellWithReuseIdentifier:HNSH_GroupChatInfoSwitchCellID];
    [self.collectionView registerClass:[HNSH_GroupChatInfoCommonCell class] forCellWithReuseIdentifier:HNSH_GroupChatInfoCommonCellID];
    
    [self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"UICollectionReusableView"];
    
    [self.collectionView registerClass:[HNSH_GroupChatInfoMoreFooterView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:HNSH_GroupChatInfoMoreFooterViewID];
    [self.collectionView registerClass:[HNSH_GroupChatInfoChatFooterView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:HNSH_GroupChatInfoChatFooterViewID];
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    [self loadMembersDataAndShowTitle:YES];
        
    [self loadGroupInfo];
}

//MARK: Myself Methods
- (void)addAllViews{
}

//MARK: 刷新界面的通知
- (void)addObs{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshUI) name:kRefreshGroupInfo object:nil];
}

- (void)refreshUI{
    [self getTitlesData];
}

//MARK: 获取群成员信息
- (void)loadMembersDataAndShowTitle:(BOOL)show {
    [HNSH_ChatNetServer requestRongCloudGroupMemberListWithGroupId:self.targetId pageNum:1 success:^(ST_BaseNetModel * _Nullable responseObject) {
        if (responseObject.code == 0) {
            NSArray * data = responseObject.resultset[@"list"];
            self.membersArray = [NSArray yy_modelArrayWithClass:HNSH_ChatFriendModel.class json:data];
            self.showMembersArray = [self getShowMembersArray];
            self.totalCount = [responseObject.resultset[@"totalCount"] integerValue];
            if (show) {
                [self getTitlesData];
            } else {
                [self.collectionView reloadSections:[NSIndexSet indexSetWithIndex:0]];
            }
        }
    } Failure:^(NSError * _Nullable error) {
        
    }];
}

- (NSArray *)getShowMembersArray{
    NSMutableArray * membersArray = [@[] mutableCopy];
    if (self.membersArray.count <= showMoreFooterCount) {
        [membersArray addObjectsFromArray:self.membersArray];
    } else {
        for (int i = 0; i < showMoreFooterCount; i++) {
            HNSH_ChatFriendModel * model = self.membersArray[i];
            [membersArray addObject:model];
        }
    }
    return membersArray.copy;
}

//MARK: 文字列表
- (void)getTitlesData{
    [[RCIMClient sharedRCIMClient] getConversationNotificationStatus:ConversationType_GROUP targetId:self.targetId success:^(RCConversationNotificationStatus nStatus) {
        dispatch_async(dispatch_get_main_queue(), ^{
            if (nStatus == DO_NOT_DISTURB) {
                [self setDefaultDataWithisOn:YES];
            } else {
                [self setDefaultDataWithisOn:NO];
            }
        });
    } error:^(RCErrorCode status) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [self setDefaultDataWithisOn:NO];
        });
    }];
}

- (void)setDefaultDataWithisOn:(BOOL)isOn{
    NSDictionary * mcDic = @{@"title":@"群聊名称", @"des":self.groupModel.name ? : @""};
//    NSDictionary * qtxDic = @{@"title":@"群头像", @"des":self.groupModel.portrait_url};
    NSDictionary * ewmDic = @{@"title":@"群二维码", @"des":@""};
    NSDictionary * ggDic = @{@"title":@"群公告", @"des":self.groupModel.bulletin ? : @""};
    NSDictionary * glDic = @{@"title":@"群管理", @"des":@""};
    NSDictionary * bzDic = @{@"title":@"备注", @"des":@""};
    NSDictionary * drDic = @{@"title":@"消息免打扰", @"des":@"", @"isOn":@(isOn)};
//    NSDictionary * ztDic = @{@"title":@"邀请直推进群", @"des":@""};
    NSDictionary * clearDic = @{@"title":@"清空聊天记录", @"des":@""};
    NSArray * secArray;
    NSArray * thrArray;
    if (self.role == 1) {
        //群管理
        secArray = @[ewmDic, ggDic, bzDic];
        thrArray = @[drDic, clearDic];
    } else if (self.role == 10) {
        //群主
        secArray = @[mcDic, ewmDic, ggDic, glDic, bzDic];
        thrArray = @[drDic, clearDic];
    } else {
        //成员
        secArray = @[ewmDic, bzDic];
        thrArray = @[drDic, clearDic];
    }
    self.titlesArray = @[
        @[],
        secArray,
        thrArray
    ];
    [self.collectionView reloadData];
}

- (void)loadGroupInfo{
    [HNSH_ChatNetServer requestRongCloudGroupInfoWithGroupId:self.targetId success:^(ST_BaseNetModel * _Nullable responseObject) {
        if (responseObject.code == 0) {
            NSDictionary * data = responseObject.resultset;
            RCGroup * group = [[RCGroup alloc] init];
            group.groupId = data[@"encode_id"];
            NSString * displayName = data[@"display_name"];
            group.groupName = displayName.length ? displayName : data[@"name"];
            group.portraitUri = data[@"portrait_url"];
            [[RCIM sharedRCIM] refreshGroupInfoCache:group withGroupId:self.targetId];
            
            HNSH_GroupInfoUserModel * model = [HNSH_GroupInfoUserModel yy_modelWithDictionary:data];
            self.groupModel = model;
            self.role = self.groupModel.member_role;
            [self getTitlesData];
        }
    } Failure:^(NSError * _Nullable error) {
        
    }];
}

//MARK: 退出
- (void)leaveGroup{
    WeakSelf(weakSelf);
    [HNSH_AlertView showTitle:@"确定要退出该群聊，并清空所有消息吗？" des:@"" buttonTitle:@"确定" buttonColor:[UIColor appGreenColor] buttonClick:^{
        //
        [weakSelf clear];
        //
        [weakSelf quit];
    }];
}

- (void)quit{
    [HNSH_ChatNetServer requestRongCloudGroupQuitWithGroupId:self.targetId success:^(ST_BaseNetModel * _Nullable responseObject) {
        if (responseObject.code == 0) {
            [self.view makeToast:@"退出成功"];
            //删除消息
            [[RCIMClient sharedRCIMClient] clearMessages:ConversationType_GROUP targetId:self.targetId];
            //删除本地会话
            [[RCIMClient sharedRCIMClient] removeConversation:ConversationType_GROUP targetId:self.targetId];
            [self.navigationController popToRootViewControllerAnimated:YES];
        }
    } Failure:^(NSError * _Nullable error) {
        
    }];
}

//MARK: 清空消息
- (void)clearAllMessage{
    WeakSelf(weakSelf);
    [HNSH_AlertView showTitle:@"确定要清空所有消息吗？" des:@"" buttonTitle:@"确定" buttonColor:[UIColor appGreenColor] buttonClick:^{
        //
        [weakSelf clear];
    }];
}

- (void)clear{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"kClearGroupMessage" object:nil];
    [self.navigationController popViewControllerAnimated:YES];
//    [[RCIMClient sharedRCIMClient] clearHistoryMessages:ConversationType_GROUP targetId:self.targetId recordTime:[CFBHelper getNowTimeTimestamp].longLongValue clearRemote:YES success:^{
//
//    } error:^(RCErrorCode status) {
//
//    }];
}

- (void)more{
    HNSH_GroupMembersViewController * vc = [HNSH_GroupMembersViewController new];
    vc.targetId = self.targetId;
    vc.role = self.role;
    [self.navigationController pushViewController:vc animated:YES];
}

//MARK: Setter Methods
- (void)setTotalCount:(NSInteger)totalCount{
    _totalCount = totalCount;
    
    self.navView.titleLabel.text = [NSString stringWithFormat:@"聊天信息"];
}

- (void)setGroupModel:(HNSH_GroupInfoUserModel *)groupModel{
    _groupModel = groupModel;
    
    self.navView.titleLabel.text = [NSString stringWithFormat:@"聊天信息"];
}

//MARK: 获取身份 1-管理员 10-群主 0-成员
- (NSInteger)getCurrentRole{
    NSInteger role = 0;
    for (HNSH_ChatFriendModel * model in self.membersArray) {
        if ([model.user.user_id isEqualToString:[ST_UserManager shareInstance].user.uid]) {
            return model.role;
        }
    }
    return role;
}

//MARK: 修改开关状态
- (void)switchViewAction:(UISwitch *)sender{
    [[RCChannelClient sharedChannelManager] setConversationNotificationLevel: ConversationType_GROUP targetId:self.targetId level:sender.isOn ? RCPushNotificationLevelMention : RCPushNotificationLevelAllMessage success:^{
        NSLog(@"消息免打扰切换成功");
    } error:^(RCErrorCode status) {
        NSLog(@"消息免打扰切换 ==> %ld",status);
    }];
}

//MARK: 开启邀请直推
- (void)openButtonAction {
    WeakSelf(weakSelf);
    [HNSH_AlertView showTitle:@"提示" des:@"开启后，将会邀请自己的直推进群，请确认是否开启？" buttonTitle:@"确定" buttonColor:[UIColor appGreenColor] buttonClick:^{
        //
        [weakSelf loadGroupInviteFansWithButton];
    }];
}

- (void)loadGroupInviteFansWithButton {
    [HNSH_ChatNetServer requestRongCloudGroupInviteFansWithGroupId:self.targetId success:^(ST_BaseNetModel * _Nullable responseObject) {
        if (responseObject.code == 0) {
            [self.view makeToast:@"开启成功"];
            [self loadMembersDataAndShowTitle:NO];
        }
    } Failure:^(NSError * _Nullable error) {
        
    }];
}

//修改群头像
- (void)loadChangePortrait:(NSString *)headerUrl {
    [HNSH_ChatNetServer requestRongCloudGroupChangePortraitWithGroupId:self.targetId portrait_url:headerUrl success:^(ST_BaseNetModel * _Nullable responseObject) {
        if (responseObject.code == 0) {
            [self loadGroupInfo];
        }
    } Failure:^(NSError * _Nullable error) {
        
    }];
}



//MARK: UICollectionViewDelegate Methods
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return self.titlesArray.count;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    if (section == 0) {
        if (self.role) {
            return self.showMembersArray.count + 2;
        } else {
            return self.showMembersArray.count + 1;
        }
    }
    return self.titlesArray[section].count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        if (indexPath.row > self.showMembersArray.count) {
            HNSH_GroupMembersChangeCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:HNSH_GroupMembersChangeCellID forIndexPath:indexPath];
            cell.isDelete = YES;
            return cell;
        } else if (indexPath.row == self.showMembersArray.count) {
            HNSH_GroupMembersChangeCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:HNSH_GroupMembersChangeCellID forIndexPath:indexPath];
            cell.isDelete = NO;
            return cell;
        } else {
            HNSH_GroupMembersCommonCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:HNSH_GroupMembersCommonCellID forIndexPath:indexPath];
            cell.model = self.membersArray[indexPath.row];
            return cell;
        }
    }
    else {
        NSDictionary * dic = self.titlesArray[indexPath.section][indexPath.row];
        NSString * title = dic[@"title"];
        if ([title isEqualToString:@"消息免打扰"]) {
            HNSH_GroupChatInfoSwitchCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:HNSH_GroupChatInfoSwitchCellID forIndexPath:indexPath];
            cell.dic = dic;
            cell.switchView.hidden = NO;
            cell.openButton.hidden = YES;
            [cell.switchView addTarget:self action:@selector(switchViewAction:) forControlEvents:UIControlEventValueChanged];
            return cell;
        } else {
            HNSH_GroupChatInfoCommonCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:HNSH_GroupChatInfoCommonCellID forIndexPath:indexPath];
            cell.dic = dic;
            return cell;
        }
    }
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        CGFloat width = (kScreenWidth - 40 - 28*4) / 5;
        return CGSizeMake(width, width + 5 + 17);
    } else {
        return CGSizeMake(collectionView.frame.size.width, 50);
    }
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    if (section == 0) {
        return UIEdgeInsetsMake(16, 28, 16, 16);
    }
    return UIEdgeInsetsMake(0, 0, 0, 0);
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
    if (section == 0) {
        return 16;
    }
    return 0;
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
    if (section == 0) {
        return 28;
    }
    return 0;
}

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
    if (kind == UICollectionElementKindSectionHeader) {
        UICollectionReusableView * view = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"UICollectionReusableView" forIndexPath:indexPath];
        view.backgroundColor = [UIColor appBGColor];
        return view;
    }
    if (kind == UICollectionElementKindSectionFooter) {
        if (indexPath.section == 0 && self.membersArray.count >= showMoreFooterCount) {
            HNSH_GroupChatInfoMoreFooterView * view = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:HNSH_GroupChatInfoMoreFooterViewID forIndexPath:indexPath];
            
            WeakSelf(weakSelf);
            view.moreBlock = ^{
                [weakSelf more];
            };
            return view;
        }
        if (indexPath.section == 2) {
            HNSH_GroupChatInfoChatFooterView * view = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:HNSH_GroupChatInfoChatFooterViewID forIndexPath:indexPath];
            
            WeakSelf(weakSelf);
            view.clearBlock = ^{
                [weakSelf clearAllMessage];
            };
            view.deleteBlock = ^{
                [weakSelf leaveGroup];
            };
            return view;
        }
    }
    return nil;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
    return CGSizeMake(collectionView.frame.size.width, 8);
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section{
    if (section == 0 && self.membersArray.count >= showMoreFooterCount) {
        return CGSizeMake(collectionView.frame.size.width, 50);
    }
    if (section == 2) {
        return CGSizeMake(collectionView.frame.size.width, 60);
    }
    return CGSizeZero;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        if (indexPath.row > self.showMembersArray.count) {
            //删除
            HNSH_DeleteMembersViewController * vc = [HNSH_DeleteMembersViewController new];
            vc.targetId = self.targetId;
            [self.navigationController pushViewController:vc animated:YES];
        } else if (indexPath.row == self.showMembersArray.count) {
            //添加
            HNSH_AddMembersViewController * vc = [HNSH_AddMembersViewController new];
            vc.targetId = self.targetId;
            [self.navigationController pushViewController:vc animated:YES];
        } else {
            HNSH_ChatFriendModel * model = self.showMembersArray[indexPath.row];
            HNSH_ChatFriendDetailViewController * vc = [HNSH_ChatFriendDetailViewController new];
            vc.rcUserId = model.user.uid;
            [self.navigationController pushViewController:vc animated:YES];
        }
    } else {
        NSDictionary * dic = self.titlesArray[indexPath.section][indexPath.row];
        NSString * title = dic[@"title"];
        if ([title isEqualToString:@"群聊名称"]) {
            HNSH_GroupNameViewController * vc = [HNSH_GroupNameViewController new];
            vc.targetId = self.targetId;
            vc.name = self.groupModel.name;
            [self.navigationController pushViewController:vc animated:YES];
        }
        if ([title isEqualToString:@"群二维码"]) {
            HNSH_GroupQRCodeViewController * vc = [HNSH_GroupQRCodeViewController new];
            vc.targetId = self.targetId;
            vc.name = self.groupModel.name;
            [self.navigationController pushViewController:vc animated:YES];
        }
        if ([title isEqualToString:@"群公告"]) {
            HNSH_GroupNoticeViewController * vc = [HNSH_GroupNoticeViewController new];
            vc.targetId = self.targetId;
            vc.bulletin = self.groupModel.bulletin;
            vc.name = self.groupModel.name;
            [self.navigationController pushViewController:vc animated:YES];
        }
        if ([title isEqualToString:@"群管理"]) {
            HNSH_GroupManageViewController * vc = [HNSH_GroupManageViewController new];
            vc.targetId = self.targetId;
            [self.navigationController pushViewController:vc animated:YES];
        }
        if ([title isEqualToString:@"备注"]) {
            HNSH_GroupRemarkViewController * vc = [HNSH_GroupRemarkViewController new];
            vc.targetId = self.targetId;
            vc.name = self.groupModel.name;
            [self.navigationController pushViewController:vc animated:YES];
        }
        if ([title isEqualToString:@"群头像"]) {
//            QLGroupChatChangeHeaderAlert *alert = [[QLGroupChatChangeHeaderAlert alloc]init];
//            [alert showView];
//            __weak __typeof(&*self)weakSelf = self;
//            alert.changeBlock = ^(NSInteger index) {
//                if (index == 0) {
//                    [DLAuthTool requestForPhotoAuth:^(BOOL isAuth) {
//                        if (isAuth) {
//                            [self startChooseImage:UIImagePickerControllerSourceTypePhotoLibrary];
//                        } else {
//                            [MBProgressHUD showText:@"未获得权限，无法上传图片"];
//                        }
//                    }];
//                } else if (index == 1) {
//                    [DLAuthTool requestCameragraph:^(BOOL isAuth) {
//                        if (isAuth) {
//                            [self startChooseImage:UIImagePickerControllerSourceTypeCamera];
//                        } else {
//                            [MBProgressHUD showText:@"未获得权限，无法上传图片"];
//                        }
//                    }];
//                }
//            };
        }
        if ([title isEqualToString:@"清空聊天记录"]) {
            [self clearAllMessage];
        }
        if ([title isEqualToString:@"邀请直推进群"]) {
            [self openButtonAction];
        }
    }
}

- (void)startChooseImage:(UIImagePickerControllerSourceType)sourceType{
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
    imagePicker.allowsEditing = YES;
    imagePicker.delegate = self;
    imagePicker.sourceType = sourceType;
    imagePicker.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    imagePicker.modalPresentationStyle = UIModalPresentationFullScreen;
    [[UIViewControllerHelper findCurrentShowingViewController] presentViewController:imagePicker animated:YES completion:nil];
}

#pragma mark - UIImagePickerControllerDelegate Methods
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
    [picker dismissViewControllerAnimated:YES completion:^{
        NSData * data = UIImageJPEGRepresentation([info objectForKey:UIImagePickerControllerEditedImage], 0.5);
        if (!data) {
            data = UIImageJPEGRepresentation([info objectForKey:UIImagePickerControllerOriginalImage], 0.5);
        }
        [self commitImgToAliyunOSS:data];
    }];
}

//MARK: 上传图片到七牛
- (void)commitImgToAliyunOSS:(NSData *)imgData{
    UIImage * image = [UIImage imageWithData:imgData];
    __weak __typeof(&*self)weakSelf = self;
    [ST_BaseNetManager uploadImageWithImageData:image progress:^(NSString *key, float percent) {
        
    } complate:^(NSString * _Nonnull urlString) {
        if ([urlString isNotBlank]) {
            [weakSelf loadChangePortrait:urlString];
        }
    }];
}

@end
